<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>

<ui:composition  xmlns="http://www.w3.org/1999/xhtml"
                 xmlns:ui="http://java.sun.com/jsf/facelets"
                 xmlns:f="http://java.sun.com/jsf/core"
                 xmlns:h="http://java.sun.com/jsf/html"
                 xmlns:c="http://java.sun.com/jsp/jstl/core"
                 xmlns:pou="http://primefaces.org/ui">
    <!-- ${facesContext.externalContext.requestContextPath} -->
    <h:head>
        <link  type="text/css" rel="stylesheet" href="#{request.contextPath}/js/jquery.jqplot.css" ></link>
        <script  type="text/javascript" src="#{request.contextPath}/js/jquery.js"></script>
        <script  type="text/javascript" src="#{request.contextPath}/js/jquery.jqplot.js"></script>
        <script type="text/javascript"  src="#{request.contextPath}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
        <script  type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.barRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.categoryAxisRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.pointLabels.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.pieRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.donutRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.dateAxisRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.canvasAxisTickRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.categoryAxisRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.barRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.canvasTextRenderer.min.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/plugins/jqplot.canvasAxisLabelRenderer.min.js"></script>

        <script type="text/javascript" src="#{request.contextPath}/js/html2canvas.js.js"></script>
        <!-- Scripts in development mode -->
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/libs/FileSaver.js/FileSaver.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/libs/BlobBuilder.js/BlobBuilder.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.addimage.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.from_html.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.ie_below_9_shim.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.sillysvgrenderer.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.split_text_to_size.js"></script>
        <script type="text/javascript" src="#{request.contextPath}/js/jsPDF/jspdf.plugin.standard_fonts_metrics.js"></script>

        <script type="text/javascript">
            var limit = 7;
            var counter = 0;
            var canvasList = new Array();

            function watcher() {
                if (counter === limit) {
                    var doc = new jsPDF();
                    doc.text(20, 20, 'Uno Petrol - #{mbSummary.mesInicio+1}/#{mbSummary.anioInicio} -#{mbSummary.lineaNegocioSeleccionada.nombre} - #{mbSummary.unidadNegocioSeleccionada.nombre}');
                            doc.addImage(canvasList[0].toDataURL('image/jpeg'), 'JPEG', 15, 30, 120, 50);
                    doc.addImage(canvasList[1].toDataURL('image/jpeg'), 'JPEG', 15, 130, 120, 50);
                    doc.addPage();
                    doc.addImage(canvasList[2].toDataURL('image/jpeg'), 'JPEG', 15, 10, 120, 50);
                    doc.addImage(canvasList[3].toDataURL('image/jpeg'), 'JPEG', 15, 105, 120, 50);
                    doc.addImage(canvasList[4].toDataURL('image/jpeg'), 'JPEG', 15, 200, 120, 50);
                    doc.addPage();
                    doc.addImage(canvasList[5].toDataURL('image/jpeg'), 'JPEG', 15, 10, 120, 50);
                    doc.addImage(canvasList[6].toDataURL('image/jpeg'), 'JPEG', 15, 105, 120, 50);
                    doc.output('datauri');
                   // doc.save("graficas.pdf");
                } else {
                    setTimeout(watcher, 1000);
                }
            }
            function topdf() {
                html2canvas(document.getElementById('histchart'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('histchart1'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('donut'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('donut1'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('chart7'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('chart5'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });
                html2canvas(document.getElementById('chart8'), {
                    onrendered: function(canvas) {
                        canvasList.push(canvas);
                        counter++;
                    }
                });

                setTimeout(watcher, 500);
                return false;
            }

        </script>

       
    </h:head>   
    <pou:button style="font-size: 12px;" onclick="javascript:topdf();" value="Descargar"></pou:button>
    <div style="width: 100%; float: left;overflow: auto">
        <ui:include src="grafHistVentasExposicion.xhtml" />
        <ui:include src="grafHistVentasOverdue.xhtml" />
    </div>   
    <div style="width: 100%; float: left;overflow: auto">
        <ui:include src="grafCarteraAntiguedad.xhtml"  />
        <ui:include src="grafCarteraAntiguedadNextMonth.xhtml"  />
    </div>    
    <div style="width: 100%; float: left;overflow: auto">    
        <ui:include src="grafOrdenesRetenidas.xhtml" />
        <ui:include src="grafMotivosRetencionOrdenes.xhtml" />
    </div>    
    <div style="width: 100%; float: left;overflow: auto">    
        <ui:include src="grafChequesRechazados.xhtml" />
    </div>    
    <div style="width: 100%; float: left;">  
        <ui:include src="grafOverdueYTDTarget.xhtml" />
        <ui:include src="grafDSOYTDTarget.xhtml" />
    </div> 
</ui:composition>

